/**
 * Created by wm123 on 2017/7/13.
 */
const { GameServer } = require('board-game');
const { server } = require('./config');

const TankGame = require('./game');
const TankBoard = require('./board');
const TankRole = require('./role');

const watchBattle = (watch, game) => game && watch(game.battle, 'battle');

GameServer.start({
    directionStart: ({ role, data }) => role.directionStart(data),
    directionEnd: ({ role, data }) => role.directionEnd(data),
    relive: ({ role, data }) => role.relive(data),
    shot: ({ role }) => role.shot(),
    login: [
        ({ watch, game }) => watchBattle(watch, game),
    ],
    ready: [
        ({ watch, game }) => watchBattle(watch, game),
    ]
}, {
    Game: TankGame,
    Board: TankBoard,
    Role: TankRole
}, server, {
    index: './web/index.js',
    compress: process.env.NODE_ENV !== 'development',
    watch: process.env.NODE_ENV === 'development',
    stats: 'verbose'
});